package com.chat.demo.userservice.Entity.DAO;

import com.chat.demo.userservice.DTO.Group.UserJoinedRoomDTO;
import com.chat.demo.userservice.Entity.Entity.UserChatRoom;
import com.chat.demo.userservice.Entity.Entity.UserChatRoomKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserChatRoomDao {
    @Select("""
                SELECT r.room_id, r.room_name, r.creator_id, r.created_at, r.type, r.description,
                       ucr.role, ucr.joined_at
                FROM app.user_chat_room ucr
                JOIN app.chat_room r ON ucr.room_id = r.room_id
                WHERE ucr.user_id = #{userId}
            """)
    List<UserJoinedRoomDTO> getJoinedRoomsByUserId(@Param("userId") Long userId);


    int deleteByPrimaryKey(UserChatRoomKey key);

    int insert(UserChatRoom record);

    int insertSelective(UserChatRoom record);

    UserChatRoom selectByPrimaryKey(UserChatRoomKey key);

    int updateByPrimaryKeySelective(UserChatRoom record);

    int updateByPrimaryKey(UserChatRoom record);
}